//
//  MyTabbarController.m
//  晓礼
//
//  Created by qianfeng on 15/11/10.
//  Copyright © 2015年 qianfeng. All rights reserved.
//

#import "MyTabbarController.h"
#import "FindViewController.h"
#import "MineViewController.h"
#import "RelationViewController.h"
#import "GiftViewController.h"
#import "UIImage+TransformSize.h"
@interface MyTabbarController ()

@end

@implementation MyTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIStoryboard * mine = [UIStoryboard storyboardWithName:@"Mine" bundle:nil];
    UINavigationController * mineNav = [mine instantiateInitialViewController];
    
    UIStoryboard * find = [UIStoryboard storyboardWithName:@"Find" bundle:nil];
    UINavigationController * findNav = [find instantiateInitialViewController];
    
    UIStoryboard * gift = [UIStoryboard storyboardWithName:@"Gift" bundle:nil];
    UINavigationController * giftNav = [gift instantiateInitialViewController];
    
    UIStoryboard * relation= [UIStoryboard storyboardWithName:@"Relation" bundle:nil];
    UINavigationController * relationNav = [relation instantiateInitialViewController];
    
    
    [self setItemWithController:relationNav.viewControllers.firstObject title:@"关系管理" imageName:@"tab_icon_grey_guanxiguanli" selectedImageName:@"tab_icon_red_guanxiguanli" nav:relationNav];
    
    [self setItemWithController:giftNav.viewControllers.firstObject title:@"情礼攻略" imageName:@"tab_icon_grey_qingligonglve" selectedImageName:@"tab_icon_red_qingligonglve" nav:giftNav];
    
    [self setItemWithController:findNav.viewControllers.firstObject title:@"发现" imageName:@"tab_icon_grey_faxian" selectedImageName:@"tab_icon_red_faxian" nav:findNav];
    
    [self setItemWithController:mineNav.viewControllers.firstObject title:@"我的" imageName:@"tab_icon_grey_wode" selectedImageName:@"tab_icon_red_wode" nav:mineNav];
}

- (void)setItemWithController:(UIViewController *)controller title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName
                          nav:(UINavigationController *)nav
{
    controller.tabBarItem.title = title;
    
    controller.tabBarItem.image = [[UIImage imageNamed:imageName] imageTransformtoSize:CGSizeMake(32, 32)];
    
    controller.tabBarItem.selectedImage = [[[UIImage imageNamed:selectedImageName]imageTransformtoSize:CGSizeMake(32, 32)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    controller.view.backgroundColor = [UIColor whiteColor];
    //controller.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    
    NSDictionary * attributes = @{NSForegroundColorAttributeName:[UIColor colorWithRed:1.000 green:0.027 blue:0.225 alpha:1.000]};
    [controller.tabBarItem setTitleTextAttributes:attributes forState:UIControlStateSelected];
    
    nav.navigationBar.barTintColor = [UIColor colorWithRed:0.743 green:0.007 blue:0.030 alpha:1.000];
    [self addChildViewController:nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
